package codesound;

import javax.sound.midi.Track;

import codesound.lexer.analysis.*;
import codesound.lexer.node.*;

public class Translation extends DepthFirstAdapter{
	
	Helper n = new Helper();
	Track track = Helper.sq.createTrack();
	int cont = 0;

    @Override
    public void caseANotelistPNotelist(ANotelistPNotelist node)
    {
        inANotelistPNotelist(node);
        if(node.getPNote() != null)
        {
        	//Helper.init();
            node.getPNote().apply(this);
        }
        if(node.getPNotelist() != null)
        {
        	//Helper.init();
            node.getPNotelist().apply(this);
        }
        outANotelistPNotelist(node);
    }


    @Override
    public void caseASinglenotePNotelist(ASinglenotePNotelist node)
    {
        inASinglenotePNotelist(node);
        if(node.getPNote() != null)
        {
            node.getPNote().apply(this);
        }
        outASinglenotePNotelist(node);
    }


    @Override
    public void caseADoPNote(ADoPNote node)
    {
        inADoPNote(node);
        if(node.getPDo() != null)
        {
            node.getPDo().apply(this);
        }
        outADoPNote(node);
    }


    @Override
    public void caseARePNote(ARePNote node)
    {
        inARePNote(node);
        if(node.getPRe() != null)
        {
            node.getPRe().apply(this);
        }
        outARePNote(node);
    }


    @Override
    public void caseAMiPNote(AMiPNote node)
    {
        inAMiPNote(node);
        if(node.getPMi() != null)
        {
            node.getPMi().apply(this);
        }
        outAMiPNote(node);
    }


    @Override
    public void caseAFaPNote(AFaPNote node)
    {
        inAFaPNote(node);
        if(node.getPFa() != null)
        {
            node.getPFa().apply(this);
        }
        outAFaPNote(node);
    }


    @Override
    public void caseASolPNote(ASolPNote node)
    {
        inASolPNote(node);
        if(node.getPSol() != null)
        {
            node.getPSol().apply(this);
        }
        outASolPNote(node);
    }


    @Override
    public void caseALaPNote(ALaPNote node)
    {
        inALaPNote(node);
        if(node.getPLa() != null)
        {
            node.getPLa().apply(this);
        }
        outALaPNote(node);
    }


    @Override
    public void caseASiPNote(ASiPNote node)
    {
        inASiPNote(node);
        if(node.getPSi() != null)
        {
            node.getPSi().apply(this);
        }
        outASiPNote(node);
    }


    @Override
    public void caseAPDo(APDo node)
    {
        inAPDo(node);
        if(node.getDo() != null)
        {
        	track.add(Helper.createNoteOnEvent(60, cont++));
			track.add(Helper.createNoteOffEvent(60,cont++));
        }
        outAPDo(node);
    }


    @Override
    public void caseAPRe(APRe node)
    {
        inAPRe(node);
        if(node.getRe() != null)
        {
        	track.add(Helper.createNoteOnEvent(62, cont++));
			track.add(Helper.createNoteOffEvent(62,cont++));
        }
        outAPRe(node);
    }


    @Override
    public void caseAPMi(APMi node)
    {
        inAPMi(node);
        if(node.getMi() != null)
        {
        	track.add(Helper.createNoteOnEvent(64, cont++));
			track.add(Helper.createNoteOffEvent(64,cont++));
        }
        outAPMi(node);
    }


    @Override
    public void caseAPFa(APFa node)
    {
        inAPFa(node);
        if(node.getFa() != null)
        {
        	track.add(Helper.createNoteOnEvent(65, cont++));
			track.add(Helper.createNoteOffEvent(65,cont++));
        }
        outAPFa(node);
    }


    @Override
    public void caseAPSol(APSol node)
    {
        inAPSol(node);
        if(node.getSol() != null)
        {
        	track.add(Helper.createNoteOnEvent(67, cont++));
			track.add(Helper.createNoteOffEvent(67,cont++));
        }
        outAPSol(node);
    }


    @Override
    public void caseAPLa(APLa node)
    {
        inAPLa(node);
        if(node.getLa() != null)
        {
        	track.add(Helper.createNoteOnEvent(69, cont++));
			track.add(Helper.createNoteOffEvent(69,cont++));
        }
        outAPLa(node);
    }


    @Override
    public void caseAPSi(APSi node)
    {
        inAPSi(node);
        if(node.getSi() != null)
        {
        	track.add(Helper.createNoteOnEvent(71, cont++));
			track.add(Helper.createNoteOffEvent(71,cont++));
        }
        outAPSi(node);
    }
	
	public long tim(){
		cont += 0.5;
		return cont;
	}

}
